<template>
  <div>
    <el-button @click.stop="add('2')">添加数据</el-button>
    <!-- 点击新增按钮，打开Win对应的弹窗，通过传给子组件一个dialogVisit来控制 -->
    <List ref="list" @edit="edit"></List>
    <Win ref="info" :types="openType" :isShow="isShow" @updates="updates" @update="update"></Win>
  </div>
</template>

<script>
import List from './List.vue'
import Win from './Win.vue'
export default {
  name: 'MyUser',
  components: {
    Win,
    List
  },
  data () {
    return {
      openType: 'add',
      isShow: false
    }
  },
  methods: {
    updates () {
      this.isShow = false
    },
    add (num) {
      // eslint-disable-next-line
      if (num == '2') {
        // 打开弹窗
        this.isShow = true
        this.openType = 'add'
        this.$refs.info.setVal({
          roleid: 0,
          username: '',
          password: '',
          status: 1
        })
      }
    },
    edit (info) {
      // eslint-disable-next-line
      if (info.status == 1) {
        // 打开弹窗
        this.isShow = true
        this.openType = 'edit'
        this.$refs.info.setVal(info)
      }
    },
    update () {
      // 这个函数会在修改或者新增成功后执行，会触发list的重新加载
      this.$refs.list.getTableNum()
    }
  }
}
</script>

<style lang="less" scoped>
</style>
